# coding = UTF-8
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split

from sklearn.linear_model import LinearRegression
import pandas as pd

datas=pd.read_csv("household_power_consumption_1000.txt",sep=";")


X=datas.iloc[:,2:4]
Y=datas.iloc[:,5]

trainX,testX,trainY,testY=train_test_split(X,Y,test_size=0.2)

model=LinearRegression()
model.fit(trainX,trainY)
yhat=model.predict(testX)

# model.score(testX,testY)
import matplotlib.pyplot as plt
plt.figure()

plt.plot(range(len(yhat)),yhat,label="predict",color="red")
plt.plot(range(len(testY)),testY,label="test",color="green")
 
plt.legend()
plt.show()
